<style>
</style>
<template>
  <list_url ref="list_url" :config="config">
    <template #action="{row}">
      <el-button v-if="0" @click="to_edit(row)" size="small">编辑</el-button>
<!--      <el-button @click="to_form_param(row)" size="small">参数管理</el-button>-->
      <el-button @click="to_action(row)" size="small">操作管理</el-button>
    </template>
  </list_url>
</template>
<script>
import {iframe, in_right_admin} from "@/js/tool.js";
import {_config} from "@/js/s94_tool.js";
import s94Mjs from "s94-js";

export default {
  props: ['__iframe'],
  data(){
    let app = this, btns = {}, is_del = this.$get('is_del');

    if (!_config('this_tenant.id')){
      if(in_right_admin('Model/add')) btns['添加模型'] = function(){ iframe('model_v2/edit', {width: '650px'}) }
    }

    let forms_config = {};
    let list_cols = {
      id: {name:'id', label:'ID', width:'65px', fixed:'left'},
      name: {name:'name', label:'模型名',min_width:'120px',align:'left'},
      label: {name:'label', label:'别名', width:'100px',align:'left'},
      parent_model: {name:'parent_model', label:'父模型', min_width:'120px',align:'left'},
      switch_sort: {name:'switch_sort', label:'排序', type:'radio_switch', width:'50px'},
      switch_pay: {name:'switch_pay', label:'支付', type:'radio_switch', width:'50px'},
      switch_price: {name:'switch_price', label:'价格', type:'radio_switch', width:'50px'},
      switch_price_vip: {name:'switch_price_vip', label:'会员价', type:'radio_switch', width:'50px'},
      switch_price_sku: {name:'switch_price_sku', label:'规格', type:'radio_switch', width:'50px'},
      switch_price_additional: {name:'switch_price_additional', label:'定制', type:'radio_switch', width:'50px'},
      switch_stock: {name:'switch_stock', label:'库存', type:'radio_switch', width:'50px'},
      switch_sales: {name:'switch_sales', label:'销量', type:'radio_switch', width:'50px'},
      switch_quota: {name:'switch_quota', label:'限购', type:'radio_switch', width:'50px'},
      switch_parent: {name:'switch_parent', label:'父级', type:'radio_switch', width:'50px'},
      switch_auto_action: {name:'switch_auto_action', label:'自动操作', type:'radio_switch', width:'50px'},
      switch_owned: {name:'switch_owned', label:'拥有', type:'radio_switch', width:'50px'},
    };
    if (is_del){
      list_cols['delete_time'] = {name:'delete_time', label:'删除时间', width:'165px', type:'datetime'};
    }else {
      list_cols['create_time'] = {name:'create_time', label:'创建时间', width:'165px'};
    }
    list_cols['action'] = {name:'action', label:'操作', width:'80px', type:'action', fixed:'right'};

    return {
      config: {
        api: '/admin/model_v2/'+(is_del?'recycle':'list'),
        title: "模型列表"+(is_del?'(已删除)':''),
        btns: btns,
        forms_config: forms_config,
        list_cols: list_cols,
        resdata: function(list){
          return list;
        },
      },
    }
  },
  methods: {
    to_edit(row){
      let can_edit = in_right_admin('ModelV2/edit') && ~[0,row.tenant_id].indexOf(_config('this_tenant.id'))
      let param = {
        id: row.id,
      }
      if (!can_edit) param['is_info'] = 1;
      iframe('model_v2/edit?'+s94Mjs.param_encode(param))
    },
    to_action(row){
      let url = '/model_v2_action/index_tab?model_name='+row.name;
      return iframe(url);
      // let url = '/model_v2_action/index?model_name='+row.name;
      // this.$router.push(url);
    },
    to_form_param(row){
      let url = '/model_v2_form_param/index?model_name='+row.name;
      this.$router.push(url);
    },
  },
  mounted() {
    let app = this;
    if (!this.__iframe) window['app'] = this;

  }
}
</script>
